package com.lagou.demo03.servlet;

import com.lagou.demo03.model.Class;
import com.lagou.demo03.service.ClassService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ClassItemServlet",urlPatterns = "/class")
public class ClassItemServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求中的学生的信息
        String className = request.getParameter("className");
        System.out.println(className);
        String grade = request.getParameter("grade");
        System.out.println(grade);
        String teacher = request.getParameter("teacher");
        System.out.println(teacher);
        String slogan = request.getParameter("slogan");
        System.out.println(slogan);
        String number = request.getParameter("classNumber");
        int classNumber = Integer.parseInt(number);
        System.out.println(classNumber);
        //创建ClassService类型的对象，实现数据的插入
        ClassService classService = new ClassService();
        Class cls = classService.classItemService(new Class(className, grade,teacher,slogan,classNumber));
        //实现客户端跳转
        response.sendRedirect("class.jsp");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
